<?php

/**
 * 服务于业务
 * User: Administrator
 * Date: 2017/12/9
 * Time: 20:17
 */
class App
{
    /**
     * 判断是否登陆过
     * @return bool
     */
    public static function checkLogic()
    {
        if (isset($_SESSION['admin_id']) && intval($_SESSION['admin_id']) > 0) {
            return true;
        }
        return false;
    }

    /**
     * 设置openid
     * @param $openId
     * @return bool
     */
    public static function setOpenid($openId)
    {
        if(isset($_COOKIE['openid'])) {
            return $_COOKIE['openid'];
        }
        setcookie('openid', $openId);
        return $openId;
    }
    /**
     * 获取|设置openid
     * @param string $openId
     * @return bool
     */
    public static function openId($openId = null)
    {
        if ($openId != null) {
            $_SESSION['openid'] = $openId;
            setcookie('openid', $openId);
            return true;
        }
        if (isset($_COOKIE['openid'])) {
            return $_COOKIE['openid'];
        }
        if (isset($_SESSION['openid'])) {
            return $_SESSION['openid'];
        }
        return false;
    }
}